﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;

/// <summary>
/// clsAuth 的摘要描述
/// </summary>
public partial class CS_clsAuth
{
    public CS_clsAuth()
    {
        //
        // TODO: 在此加入建構函式的程式碼
        //
    }
}

public partial class CS_clsAuth
{

    public static string GetMyRoleIDs()
    {
        clsDBUtility dbUtil = clsDBUtility.GetInstance();
        DataTable MyDataTable =   dbUtil.GetMyRoles(((System.Web.UI.Page)HttpContext.Current.Handler).User.Identity.Name);
        string MyRoleIDs=string.Empty;

        if(MyDataTable!=null)
        {
            List<string> _list_MyRoleIDs = new List<string>();

            foreach (DataRow DR in MyDataTable.Rows )
            {
                _list_MyRoleIDs.Add(DR["RoleID"].ToString());        
            }
            MyRoleIDs = String.Join(",", _list_MyRoleIDs.ToArray());
 
        }    
   
        return MyRoleIDs;
    }

    public static string GetMyRoleNames()
    {
        clsDBUtility dbUtil = clsDBUtility.GetInstance();
        DataTable MyDataTable = dbUtil.GetMyRoles(((System.Web.UI.Page)HttpContext.Current.Handler).User.Identity.Name);
        string MyRoleNames=string.Empty;

        if (MyDataTable != null)
        {
            List<string> _list_MyRoleNames = new List<string>();

            foreach (DataRow DR in MyDataTable.Rows)
            {
                _list_MyRoleNames.Add(DR["RoleNAme"].ToString());
            }
            MyRoleNames = String.Join(",", _list_MyRoleNames.ToArray());
        }

        return MyRoleNames;

    }









    #region Property

    public static string MyName
    {
        get
        {
            return (System.Web.HttpContext.Current.Request.Cookies["MyName"] == null ? string.Empty : HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.Cookies["MyName"].Value));
        }
        set
        {
            System.Web.HttpContext.Current.Response.Cookies["MyName"].Value = HttpContext.Current.Server.UrlEncode(value);
            System.Web.HttpContext.Current.Response.Cookies["MyName"].Expires = DateTime.Now.AddMonths(1);
        }
    }

    public static string MyOrganizationID
    {
        get
        {
            return (System.Web.HttpContext.Current.Request.Cookies["MyOrganizationID"] == null ? string.Empty : HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.Cookies["MyOrganizationID"].Value));
        }
        set
        {
            System.Web.HttpContext.Current.Response.Cookies["MyOrganizationID"].Value = HttpContext.Current.Server.UrlEncode(value);
            System.Web.HttpContext.Current.Response.Cookies["MyOrganizationID"].Expires = DateTime.Now.AddMonths(1);
        }
    }

    public static string MyOrganizationPapaID
    {
        get
        {
            return (System.Web.HttpContext.Current.Request.Cookies["MyOrganizationPapaID"] == null ? string.Empty : HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.Cookies["MyOrganizationPapaID"].Value));
        }
        set
        {
            System.Web.HttpContext.Current.Response.Cookies["MyOrganizationPapaID"].Value = HttpContext.Current.Server.UrlEncode(value);
            System.Web.HttpContext.Current.Response.Cookies["MyOrganizationPapaID"].Expires = DateTime.Now.AddMonths(1);
        }
    }

    public static string MyEmail
    {
        get
        {
            return (System.Web.HttpContext.Current.Request.Cookies["MyEmail"] == null ? string.Empty : HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.Cookies["MyEmail"].Value));
        }
        set
        {
            System.Web.HttpContext.Current.Response.Cookies["MyEmail"].Value = HttpContext.Current.Server.UrlEncode(value);
            System.Web.HttpContext.Current.Response.Cookies["MyEmail"].Expires = DateTime.Now.AddMonths(1);
        }
    }

    public static string MyUserType
    {
        get
        {
            return (System.Web.HttpContext.Current.Request.Cookies["MyUserType"] == null ? string.Empty : HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.Cookies["MyUserType"].Value));
        }
        set
        {
            System.Web.HttpContext.Current.Response.Cookies["MyUserType"].Value = HttpContext.Current.Server.UrlEncode(value);
            System.Web.HttpContext.Current.Response.Cookies["MyUserType"].Expires = DateTime.Now.AddMonths(1);
        }
    }

    //public static string MyRoleIDs
    //{
    //    get
    //    {
    //        //if (string.IsNullOrEmpty(((System.Web.UI.Page)System.Web.HttpContext.Current.Handler).User.Identity.Name))
    //        //{ 
    //        GetMyRoleIDs();              
    //        //}

    //        return HttpContext.Current.Request.Cookies["MyRoleIDs"].Value;         
    //    }

    //}

    //public static string MyRoleNames
    //{
    //    get
    //    {
    //        //if(System.Web.HttpContext.Current.Request.Cookies["MyRoleNames"] == null)
    //        //{
    //        GetMyRoles();      
    //        //}

    //        return HttpContext.Current.Request.Cookies["MyRoleNames"].Value;
         
    //    }
    //}

    #endregion


}
